package com.nattakute.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import com.nattakute.dao.StatusDAO;
import com.nattakute.model.Status;

@Repository("statusDao")
public class StatusDAOImpl implements StatusDAO{

	@Autowired
	private SessionFactory sessionFactory;
	
	@SuppressWarnings("unchecked")
	@Cacheable("status")
	public List<Status> getStatus() {
		// TODO Auto-generated method stub
		return sessionFactory.getCurrentSession().createQuery("from Status s").list();
	}

	
	public Status getStatusById(Integer id) {
		Status status = new Status();
		try {
			status = (Status)sessionFactory.getCurrentSession().get(Status.class, id);
			return status;			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}

	
	public Boolean addStatus(Status status) {
		try {
			sessionFactory.getCurrentSession().save(status);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	
	public Boolean deleteStatus(Status status) {
		try {
			sessionFactory.getCurrentSession().delete(status);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

	
	public Boolean updateStatus(Status status) {
		try {
			sessionFactory.getCurrentSession().update(status);
			return true;
		} catch (Exception e) {
			// TODO: handle exception
		}
		return false;
	}

}
